<template>
  <div class="box">
<!-- 搜索信息-->
    <div class="top">
      <el-form :inline="true" :model="queryParams" class="demo-form-inline" clearable>
        <el-form-item label="填报人">
          <el-input
            v-model="queryParams.reportFiller"
            placeholder="填报人">
          </el-input>
        </el-form-item>
        <el-form-item label="事件类型">
          <el-select v-model="queryParams.reviewEventType" placeholder="请选择事件类型判定" clearable>
            <el-option
              v-for="dict in dict.type.he_review_event_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-select v-model="queryParams.reviewStatus" placeholder="请选择上报事件类型" clearable>
            <el-option
              v-for="dict in dict.type.he_review_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
<!--        <el-form-item label="处理情况">
          <el-select v-model="queryParams.reportEventState" placeholder="请选择上报事件状态" clearable>
            <el-option
              v-for="dict in dict.type.he_report_event_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>-->
        <el-form-item label="事件等级">
          <el-select v-model="queryParams.resultsEventClassification" placeholder="请选择事件分级" clearable>
            <el-option
              v-for="dict in dict.type.he_event_classification"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="上报类型">
          <el-select filterable v-model="queryParams.reportEventType" @change="changeReportType" placeholder="请选择上报事件类型" clearable>
            <el-option
              v-for="dict in dict.type.he_report_event_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
<!--        <el-form-item>
          <el-radio-group @change="deal" v-model="operate">
            <el-radio label="01">全部</el-radio>
            <el-radio label="02">我部需处理</el-radio>
            <el-radio label="03">我部需协助</el-radio>
            <el-radio label="04">我部上报</el-radio>
          </el-radio-group>
        </el-form-item>-->
<!--        <el-form-item label="上报部门" style="margin-left: 25px">
          <el-select v-model="queryParams.reportDepartment" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.he_department_name"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="处理部门">
          <el-select v-model="queryParams.reviewDepartment" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.he_department_name"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="协助部门">
          <el-select v-model="queryParams.supportDepartmentOne" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.he_department_name"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>-->
        <el-form-item style="margin-left: 50px">
          <el-button type="primary" @click="handleQuery" size="small" >查询</el-button>
          <el-button type="primary" plain @click=" resetQuery" size="small">重置</el-button>
          <el-button type="success" size="small"  @click="openExport">导 出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 主页信息   -->
    <div class="body">
      <el-table class="shenHeTable" :data="reportList" height="550" border style="width: 100%">
        <el-table-column
          prop="reportEventNumber"
          label="编号"
          min-width="10%"
          align="center">
        </el-table-column>
        <el-table-column
          prop="reportEventState"
          label="事件审核状态"
          min-width="10%"
          align="center">
            <template slot-scope="scope">
              <el-button  v-if="scope.row.reviewStatus=='01'" disabled="disabled" style="cursor: unset" type="danger" plain size="mini"> <dict-tag :options="dict.type.he_review_status" :value="scope.row.reviewStatus"/></el-button>
              <el-button  v-if="scope.row.reviewStatus=='03'"  disabled="disabled" style="cursor: unset" type="primary" plain size="mini"> <dict-tag :options="dict.type.he_review_status" :value="scope.row.reviewStatus"/></el-button>
              <el-button  v-if="scope.row.reviewStatus=='02'"  disabled="disabled" style="cursor: unset" type="success" plain size="mini"> <dict-tag :options="dict.type.he_review_status" :value="scope.row.reviewStatus"/></el-button>
              <el-button  v-if="scope.row.reviewStatus=='04'"  disabled="disabled" style="cursor: unset" type="info" plain size="mini"> <dict-tag :options="dict.type.he_review_status" :value="scope.row.reviewStatus"/></el-button>
            </template>
          </el-table-column>

        <el-table-column
          prop="reportEventType"
          label="事件"
          min-width="10%"
          align="center">
          <template slot-scope="scope">
            <a href="#" @click="detail(scope.row)"><u style="color: #0575f6"><dict-tag :options="dict.type.he_report_event_type" :value="scope.row.reportEventType"/></u></a>
            <el-button disabled="disabled" style="margin-top: 3px; cursor: unset" type="primary" plain size="mini"> <dict-tag :options="dict.type.he_review_event_type" :value="scope.row.reviewEventType"/></el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="resultsEventClassification"
          label="事件等级"
          min-width="25%"
          align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.he_event_severity" :value="scope.row.resultsEventSeverity"/><hr>
            <dict-tag :options="dict.type.he_event_classification" :value="scope.row.resultsEventClassification"/><hr>
            <dict-tag :options="dict.type.he_severity_of_injury" :value="scope.row.resultsSeverityInjury"/>
          </template>
        </el-table-column>
        <el-table-column
          prop="reportDepartment"
          label="上报科室"
          min-width="10%"
          align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.he_department_name" :value="scope.row.reportDepartment"/>
          </template>
        </el-table-column>
        <el-table-column
          prop="reviewDepartment"
          label="呈送科室"
          min-width="10%"
          align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.he_department_name" :value="scope.row.reviewDepartment"/>
          </template>
        </el-table-column>
        <el-table-column
          prop="reportFiller"
          label="填报人"
          min-width="10%"
          align="center">
        </el-table-column>
        <el-table-column
          prop="creationTime"
          label="创建时间"
          min-width="10%"
          align="center">
        </el-table-column>
<!--        <el-table-column label="操作" align="center" min-width="15%" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-if="scope.row.reportEventState=='01'" @click="handleUpdate(scope.row)"

            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              v-if="scope.row.reportEventState=='01'"
              @click="handleDelete(scope.row)"
            >删除</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              v-if="scope.row.reportEventState=='01'"
              @click="handleDelete(scope.row)"
            >上报</el-button>
          </template>
        </el-table-column>-->
      </el-table>
      <!--  页码显示-->
      <div class="block">
        <span class="demonstration"></span>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getDeptList"
        />
<!--        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50,100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="40">
        </el-pagination>-->
      </div>
    </div>

    <el-dialog title="导出自定义字段" :visible.sync="showDownload" width="80%">
      <templateComponent bankName="he_event_dto" :note1="note1"  ref="templateC"
                         @closeDialog="showDownload=false"  @excel="exportExcel"/>
    </el-dialog>
  </div>
</template>

<script>
import { listReport,deptListReport,delReport} from "@/api/module/whd/report";
import templateComponent from "@/views/module/ny/templateComponent";
export default {
  dicts: ['he_review_status', 'he_department_name', 'he_report_event_state', 'he_report_event_type',  'he_event_severity', 'he_review_status',  'he_event_classification', 'he_review_event_type',  'he_severity_of_injury'],
  components: {templateComponent},
  data() {
    return {
      //分组标记
      note1:"",
      // 个人信息表查询参数
      queryParamsRecords: {
        pageNum: null,
        pageSize:null,
        reviewStatus:null,
        reportEventState: '',
        reportStatus:'02',
        reportDepartment:this.$store.state.user.deptid.toString(),
        reportEventNumber:null,
        reviewEventType:null,
        resultsEventClassification:null,
        reportEventType:null,
        reportFiller:null
        //reportFillerId:this.$store.state.user.userid,
      },
      // 导出弹窗
      showDownload: false,
      roledisplay:false,
      role:"",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 事件上报信息表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      operate: '',
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        reportEventNumber: null,
        basicEventId: null,
        reportEventState: '',
        reportEventType: null,
        reportFirstLevel: null,
        reportSecondLevel: null,
        situationEdescriptionProcess: null,
        situationMeasuresEvent: null,
        situationTakenMeasures: null,
        situationCausesconsequences: null,
        patientInvolved: null,
        patientId: null,
        patientNumber: null,
        patientDiagnosisCategory: null,
        patientRecordOutpatient: null,
        patientName: null,
        patientGender: null,
        patientDateOfBirth: null,
        patientAge: null,
        patientAgeStage: null,
        patientEthnicGroup: null,
        patientWeight: null,
        patientPreDisease: null,
        patientContact: null,
        patientFamilyNumber: null,
        patientAdmissionTime: null,
        patientDepartment: null,
        patientBedNumber: null,
        patientNursingLevel: null,
        patientEducationLevel: null,
        patientDiagnosis: null,
        occurrenceTime: null,
        occurrenceDate: null,
        occurrenceDateType: null,
        occurrenceTimePeriod: null,
        occurrenceLocation: null,
        occurrenceScenePhotos: null,
        partyName: null,
        partyAge: null,
        partyYearsOfExperience: null,
        partyCategory: null,
        partyEducation: null,
        partyPosition: null,
        partyPost: null,
        resultsPossibilityDispute: null,
        resultsEventSeverity: null,
        resultsEventClassification: null,
        resultsSeverityInjury: null,
        reportMethod: null,
        reportDepartmentId: null,
        reportDepartment: null,
        reportStatus: "02",
        reportFillerId: null,
        reportFiller: null,
        reportTime: null,
        reportAttachedImages: null,
        reportOtherRemarks: null,
        reviewStatus: "",
        reviewDepartmentId: null,
        reviewDepartment: null,
        reviewPersonId: null,
        reviewPerson: null,
        reviewTime: null,
        reviewAdvice: null,
        reviewEventType: null,
        fallbackStatus: null,
        fallbackReason: null,
        fallbackPersonId: null,
        fallbackPerson: null,
        invalidationStatus: null,
        invalidationReason: null,
        invalidationPersonId: null,
        invalidationPerson: null,
        handlingStatus: null,
        handlingOpinions: null,
        handlingPicture: null,
        handingPersonId: null,
        handingPerson: null,
        analyzeReports: null,
        analyzeReportsId: null,
        supportDepartmentOne: null,
        supportOneOpinions: null,
        supportOnePicture: null,
        supportOnePersonId: null,
        supportOnePerson: null,
        supportDepartmentTwo: null,
        supportTwoOpinions: null,
        supportTwoPicture: null,
        supportTwoPersonId: null,
        supportTwoPerson: null,
        eventDeterminatione: null,
        eventDeterminationeDescription: null,
        eventDeterminationePersonId: null,
        eventDeterminationePerson: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,
        creationTime: null,
        userId: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      value1: false,
      currentPage4: 4,
      activeName: 'first',
     /* showSearch: true,
      queryParams: {
        user: '',
        eventType: '',
        handlingInformation: '',
        eventLevel: '',
        reportType: '',
        value1: false,

        reportDepartment: '',
        processDepartment: '',
        assistDepartment: ''
      },*/
      tableData: [{
        number: 1,
        eventStatus: 1,
        eventDetails: 1,
        eventLevel: 1,
        reportDepartment: 1,
        submitDepartment: 1,
        informant: 1,
        time: 1
      }],
    }
  },
  /*value1:'',*/

  created() {
    console.log("登录用户是"+this.$store.state.user.deptid )
    console.log("登录用户权限是"+this.$store.state.user.roles)
    if(this.$store.state.user.roles.indexOf('auditor') > -1){
      this.role="auditor"
      this.queryParams.reportDepartment=this.$store.state.user.deptid.toString();
      this.roledisplay=true;
    }else if(this.$store.state.user.roles.indexOf('doctor') > -1){
      this.queryParams.reportFillerId=this.$store.state.user.userid
      this.role="doctor"
    }else{
     this.roledisplay=true;
      this.queryParams.reportDepartment=this.$store.state.user.deptid.toString();
    }
    // this.value1 =JSON.parse(this.$route.query.value1);
    // if(!this.value1){
    //
    //   this.queryParams.reportFillerId=this.$store.state.user.userid;
    // }
    this.queryParams.reviewEventType =this.$route.query.type;
    this.queryParams.reviewStatus =this.$route.query.state;
    /*this.getDate();*/
    this.getDeptList();
  },


  methods: {
    //选中事件类型
    changeReportType(e){
      this.note1=e

    },
    resetParamsRecords(){
      this.queryParamsRecords={
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        reportEventState: '',
        reportStatus:'02',
        reportDepartment:this.$store.state.user.deptid.toString(),
        //reportFillerId:this.$store.state.user.userid,
        reportEventNumber:null,
        reviewEventType:null,
        resultsEventClassification:null,
        reportEventType:null,
        reportFiller:null
      }
      //this.queryParamsRecords.pageNum=this.queryParams.pageNum;
      //this.queryParamsRecords.pageSize=this.queryParams.pageSize;
    },
    // 打开导出弹窗
    openExport() {
      this.resetParamsRecords();
      this.showDownload = true

      //console.log(this.queryParams.pageNum)
      //console.log(this.queryParamsRecords.pageNum)

      this.queryParamsRecords.reviewEventType=this.queryParams.reviewEventType;
      this.queryParamsRecords.resultsEventClassification=this.queryParams.resultsEventClassification;
      this.queryParamsRecords.reportEventType=this.queryParams.reportEventType;
      this.queryParamsRecords.reportFiller=this.queryParams.reportFiller;
      this.queryParamsRecords.reviewStatus=this.queryParams.reviewStatus

    },
    // 导出
    exportExcel() {
      // console.log(this.$refs['templateC'].checkList)

      this.download('project/whd/report/exportaudit/' + this.$refs['templateC'].checkList, {
        ...this.queryParamsRecords
      }, `event_file_${new Date().getTime()}.xlsx`)
    },
    getDate(){
      var date1 = new Date();
      var year1= date1.getFullYear();
      var month1 = date1.getMonth() + 1; // 月份是从0开始计数的，需要加1
      var day1 = date1.getDate();
      var formattedDate1 = year1 + "-" + (month1 < 10 ? "0" + month1 : month1)+"-"+"01" ;
      this.queryParams.note1=formattedDate1;
    },
    deal(){
      this.queryParams.reviewDepartment="";
      this.queryParams.supportDepartmentOne="";
      this.queryParams.reportDepartment="";
      if(this.operate=="01"){
        this.getDeptList();
      }else if(this.operate=="02"){
        this.queryParams.reviewDepartment=this.$store.state.user.deptid.toString();
        this.getDeptList();
      }else if(this.operate=="03"){
        this.queryParams.supportDepartmentOne=this.$store.state.user.deptid.toString();
        this.getDeptList();
      }else if(this.operate=="04"){
        this.queryParams.reportDepartment=this.$store.state.user.deptid.toString();
        this.getDeptList();
      }
    },
    shuchu(){
      if(!this.value1){
        this.queryParams.reportFillerId=this.$store.state.user.userid;
        this.getDeptList();
      }else{
        this.queryParams.reportFillerId="";
        this.getDeptList();
      }
    },
    detail(row){
      const id = row.id;
      const type=row.reportEventType
      this.$router.push({path: "/hosipitalevent/shenheindex",query: {id,type}});
    },
    /** 查询事件上报信息列表 */
    getList() {
      this.loading = true;
      listReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getDeptList() {
      this.loading = true;
      deptListReport(this.queryParams).then(response => {
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.queryParams={
        id: null,
        pageSize: 10,
        reportEventNumber: null,
        basicEventId: null,
        reportEventState: this.queryParams.reportEventState,
        reportEventType: null,
        reportFirstLevel: null,
        reportSecondLevel: null,
        situationEdescriptionProcess: null,
        situationMeasuresEvent: null,
        situationTakenMeasures: null,
        situationCausesconsequences: null,
        patientInvolved: null,
        patientId: null,
        patientNumber: null,
        patientDiagnosisCategory: null,
        patientRecordOutpatient: null,
        patientName: null,
        patientGender: null,
        patientDateOfBirth: null,
        patientAge: null,
        patientAgeStage: null,
        patientEthnicGroup: null,
        patientWeight: null,
        patientPreDisease: null,
        patientContact: null,
        patientFamilyNumber: null,
        patientAdmissionTime: null,
        patientDepartment: null,
        patientBedNumber: null,
        patientNursingLevel: null,
        patientEducationLevel: null,
        patientDiagnosis: null,
        occurrenceTime: null,
        occurrenceDate: null,
        occurrenceDateType: null,
        occurrenceTimePeriod: null,
        occurrenceLocation: null,
        occurrenceScenePhotos: null,
        partyName: null,
        partyAge: null,
        partyYearsOfExperience: null,
        partyCategory: null,
        partyEducation: null,
        partyPosition: null,
        partyPost: null,
        resultsPossibilityDispute: null,
        resultsEventSeverity: null,
        resultsEventClassification: null,
        resultsSeverityInjury: null,
        reportMethod: null,
        reportDepartmentId: this.queryParams. reportDepartmentId,
        reportDepartment: this.queryParams. reportDepartment,
        reportStatus: "02",
        reportFillerId: this.queryParams. reportFillerId,
        reportFiller: null,
        reportTime: null,
        reportAttachedImages: null,
        reportOtherRemarks: null,
        reviewStatus: null,
        reviewDepartmentId: null,
        reviewDepartment: null,
        reviewPersonId: null,
        reviewPerson: null,
        reviewTime: null,
        reviewAdvice: null,
        reviewEventType: null,
        fallbackStatus: null,
        fallbackReason: null,
        fallbackPersonId: null,
        fallbackPerson: null,
        invalidationStatus: null,
        invalidationReason: null,
        invalidationPersonId: null,
        invalidationPerson: null,
        handlingStatus: null,
        handlingOpinions: null,
        handlingPicture: null,
        handingPersonId: null,
        handingPerson: null,
        analyzeReports: null,
        analyzeReportsId: null,
        supportDepartmentOne: null,
        supportOneOpinions: null,
        supportOnePicture: null,
        supportOnePersonId: null,
        supportOnePerson: null,
        supportDepartmentTwo: null,
        supportTwoOpinions: null,
        supportTwoPicture: null,
        supportTwoPersonId: null,
        supportTwoPerson: null,
        eventDeterminatione: null,
        eventDeterminationeDescription: null,
        eventDeterminationePersonId: null,
        eventDeterminationePerson: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,
        creationTime: null,
        updateTime: null,
        userId: null,
        deptId: null
      };
      if(this.roledisplay=="true"){
        this.value1=true;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getDeptList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加事件上报信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      console.log(row)
      const id = row.id || this.ids
      const type=row.reportEventType;
      if(type=="22"){
        this.$router.push({path: "/badmedinflact",query: {id}});
      }
      console.log(id)
     /* getReport(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改事件上报信息";
      });*/
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除事件上报信息编号为"' + ids + '"的数据项？').then(function() {
        return delReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/report/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    }
  },

    handleClick(tab, event) {
      console.log(tab, event);
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }

}

</script>

<style lang="scss" scoped>
.box {
  margin-top: 25px;
  margin-left: 20px;
  margin-right: 20px;
}

.block {
  margin-top: 30px;
  text-align: center;
}
//不影响全局，使用样式穿透
  ::v-deep .el-table__body-wrapper {
// 整个滚动条
  &::-webkit-scrollbar {
     width: 0px; // 纵向滚动条的宽度
   background: rgba(213, 215, 220, 0.3);
     border: none;
   }
// 滚动条轨道
  &::-webkit-scrollbar-track {
     border: none;
   }
}
// --------------------隐藏table gutter列和内容区右侧的空白 start
   ::v-deep .shenHeTable th.gutter {
     display: none;
     width: 0
   }
::v-deep .shenHeTable colgroup col[name='gutter'] {
  display: none;
  width: 0;
}
// 这个样式不加的话内容哪里会缺一点，估计是因为滚动条哪里缺的没有补上
   ::v-deep .el-table__body {
     width: 100% !important;
   }

.shenHeTable{
::-webkit-scrollbar{
  width: 0px !important;
  height: 0px !important;
  border: none;
}
::-webkit-scrollbar-track{
  width: 0!important;height: 0;
  border: none;
}

}


</style>
